import { defineStore } from "pinia";
import { AddressList } from "vant";

export const userStore = defineStore('user',{
    state:()=>({  //数据
        addressList:[
            {
            id: 1,
            name: '张三',
            tel: '13800138000',
            address: '北京市朝阳区建国路100号',
            isDefault: true
          },
          {
            id: 2,
            name: '李四',
            tel: '13900139000',
            address: '上海市浦东新区陆家嘴环路200号',
            isDefault: false
          }],
          disabledList:[
            {
                id: '3',
                name: '王五',
                tel: '1320000000',
                address: '浙江省杭州市滨江区江南大道 15 号',
            }
          ],
          cartList:[]
    }),
    actions:{    //方法
      //增加地址
      addAddress(content){
        //只能有一个默认地址
        if(content.isDefault){
            this.addressList.forEach(item=>{
              if(item.isDefault){
                item.isDefault = false
              }
            })
        }
        this.addressList.push(content)
      },
      //编辑地址
      editAddress(content){
        this.addressList = this.addressList.map(item=>{
          if(item.isDefault){
            item.isDefault = false
          }
          return item.id === content.id ? content : item
        })
      },
      addCart(cart){
        this.cartList =cart
      }
    },
    getters:{  //获取值
        
    }
})